﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections.ObjectModel;
using System.Xml.Linq;

namespace HtmlExtractor.Config
{
    public class PageConfig :Collection<IPageItemConfig>
    {
        
        
        public string TargetUri
        {
            get;
            set;
        }
        public string Name
        { 
            get;
            set; 
        }
        public PageConfig()
        {
           
        }
        public PageConfig(XElement pageNode)
        {
            TargetUri = (string)pageNode.Element("TargetUri");
            Name = (string)pageNode.Attribute("name");
            foreach (XElement r in pageNode.Elements().Where(e => e.Name != "TargetUri"))
            {
               Add(RuleBuildFactory.Create(r));
            }
        }       

        public PageResult GetParseResult(ParserContext context)
        {
            PageResult result = new PageResult();
            result.OutputProcessorName = "";
            foreach (IPageItemConfig r in Items)
            {
                PageResult temp= r.GetParseResult(context.OriginalText,context);
                if (temp != null)
                {
                    result.AddRange(temp);
                }
            }
            return result;
        }
    }
}
